package com.feihao.zhou.TCP.demoFileUpLoadUseThreadPool;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8808);

        //创建本地文件读取流：
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\IdeaProjects\\Job-code\\day16-code-NET\\dir\\day14-网络编程01.pdf"));

        //创建网络字节写入流：
        OutputStream os = socket.getOutputStream();

        int len;
        byte[] bytes = new byte[1024];

        while ((len = bis.read(bytes)) != -1) {
            os.write(bytes, 0, len);
        }
        //给服务器结束标志：
        socket.shutdownOutput();

        //读取服务器回传信息：
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }

        //关闭资源：
        br.close();
        bis.close();
        socket.close();
    }
}
